package cn.util;

import java.util.HashMap;
import java.util.Map;

/****
 * 
 * 返回成功信息
 *
 * @Author Wang Tao
 * @Company Saike
 * @Version V2.0
 */
public class SuccessInfoUtils {
	private static final String SUCCESS = "0";
	public static final String ERROR = "400";
	private static Map<String, String> errorMap = new HashMap<String, String>();
	static {
		errorMap.put(SUCCESS, "操作成功");
		errorMap.put(ERROR, "操作失败!");
	}

	/**
	 * 设置正确 结果
	 *
	 * @param obj
	 * @return
	 */
	public static SuccessInfo setSuccessInfo(Object obj) {
		SuccessInfo successInfo = new SuccessInfo();
		successInfo.setErrorCode(SUCCESS);
		successInfo.setResult(obj);
		return successInfo;
	}

	/**
	 * 设置错误 结果
	 *
	 * @param type
	 * @return
	 */
	public static ErrorInfo setErrorInfo(String type) {
		ErrorInfo errorInfo = new ErrorInfo();
		errorInfo.setErrorMessage(SuccessInfoUtils.errorMap.get(type));
		errorInfo.setErrorCode(type);
		return errorInfo;
	}
}
